home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d16 / winvn060.arc / WVART.C < prev    next >
C/C++ Source or Header  |  1991-07-01  |  13KB  |  353 lines

  1. /*---  wvart.c ------------------------------------------- */
  2. /*  This file contains the window procedure for the Article Viewing window
  3.  *  for WinVn.
  4.  */
  5.  
  6. #include "windows.h"
  7. #ifndef MAC
  8. #include "winundoc.h"
  9. #endif
  10. #include "WVglob.h"
  11. #include "WinVn.h"
  12.  
  13. /****************************************************************************
  14.  
  15.     FUNCTION: WinVnArtWndProc(HWND, unsigned, WORD, LONG)
  16.  
  17.     PURPOSE:  Processes messages
  18.  
  19. ****************************************************************************/
  20.  
  21. long FAR PASCAL WinVnArtWndProc(hWnd, message, wParam, lParam)
  22. HWND hWnd;
  23. unsigned message;
  24. WORD wParam;
  25. LONG lParam;
  26. {
  27.     FARPROC lpProcAbout;
  28.     HMENU hMenu;
  29.  
  30.     PAINTSTRUCT ps;                              /* paint structure          */
  31.  
  32.     HDC hDC;                                    /* handle to display context */
  33.     RECT myRect;                                  /* selection rectangle      */
  34.     HWND hWndView;
  35.     HDC  hDCView;
  36.    TypDoc *ThisDoc;
  37.    TypDoc *GroupDoc;
  38.     int ih,j;
  39.     int found;
  40.     int imemo;
  41.     int CtrlState;
  42.    TypLine far *LinePtr, far *ArtLinePtr;
  43.    TypBlock far *BlockPtr, far *ArtBlockPtr;
  44.    HANDLE hBlock;
  45.    unsigned int Offset;
  46.    int reply;
  47.    int result;
  48.    char far *cptr;
  49.    TypLineID MyLineID;
  50. #ifdef MAC
  51.    int vRef;
  52. #endif
  53.  
  54.    for(ih=0,found=FALSE; !found && ih<MAXARTICLEWNDS; ih++) {
  55.      if(ArticleDocs[ih].hDocWnd == hWnd) {
  56.        found = TRUE;
  57.        ThisDoc = &(ArticleDocs[ih]);
  58.      }
  59.    }
  60.  
  61.    if(!found) {
  62.       ThisDoc = CommDoc;
  63.    }
  64.  
  65.     switch (message) {
  66.  
  67.         case WM_ACTIVATE:
  68.         case WM_SETFOCUS:
  69.             if(wParam){
  70.                ActiveArticleDoc = ThisDoc;
  71.             }
  72.             /* fall through */
  73.         case WM_SYSCOMMAND:
  74.            return (DefWindowProc(hWnd, message, wParam, lParam));
  75.  
  76.         case WM_SIZE:
  77.             GetClientRect(hWnd, &myRect);
  78.             ThisDoc->ScXWidth =  myRect.right;
  79.             ThisDoc->ScYHeight = myRect.bottom;
  80.             ThisDoc->ScYLines = (myRect.bottom - myRect.top - TopSpace) / LineHeight;
  81.             ThisDoc->ScXChars = (myRect.right - myRect.left - SideSpace) / CharWidth;
  82.             break;
  83.  
  84.          case WM_DESTROY:
  85.             ThisDoc->InUse = FALSE;
  86.             if(ThisDoc == CommDoc) {
  87.                CommBusy = FALSE;
  88.                CommDoc = (TypDoc *) NULL;
  89.             }
  90.             /* Clear the pointer in the line for this article in the   */
  91.             /* group  document.  This pointer currently points       */
  92.             /* to the current document, which we are wiping out      */
  93.             /* with the destruction of this window.                  */
  94.  
  95.             if(ThisDoc->hParentBlock) {
  96.                LockLine(ThisDoc->hParentBlock,ThisDoc->ParentOffset,ThisDoc->ParentLineID,&BlockPtr,&LinePtr);
  97.                ( (TypArticle far *)
  98.                 ( ((char far *)LinePtr)+sizeof(TypLine) ) )->ArtDoc =
  99.                  (TypDoc *)NULL;
  100.                UnlockLine(BlockPtr,LinePtr,&hBlock,&Offset,&MyLineID);
  101.             }
  102.             /* Clear document                                        */
  103.             FreeDoc(ThisDoc);
  104.  
  105.             /* If there's another article window, make it the active   */
  106.             /* artcile window so we don't create a new one if the      */
  107.             /* New Article flag is FALSE.                              */
  108.  
  109.             for(j=MAXARTICLEWNDS-1; j>=0; j--) {
  110.                if(ArticleDocs[j].InUse) {
  111.                   ActiveArticleDoc = &(ArticleDocs[j]);
  112.                   break;
  113.                }
  114.             }
  115.             break;
  116.             break;
  117.  
  118.          case WM_KEYDOWN:
  119.             /* See if this key should be mapped to a scrolling event
  120.              * for which we have programmed the mouse.  If so,
  121.              * construct the appropriate mouse call and call the mouse code.
  122.              */
  123. #ifndef MAC
  124.             if(wParam == VK_F6) {
  125.                NextWindow(ThisDoc);
  126.             } else {
  127.                CtrlState = GetKeyState(VK_CONTROL) < 0;
  128.                for(j=0; j<NUMKEYS; j++) {
  129.                   if(wParam == key2scroll[j].wVirtKey &&
  130.                    CtrlState == key2scroll[j].CtlState) {
  131.                      SendMessage(hWnd,key2scroll[j].iMessage,
  132.                       key2scroll[j].wRequest,0L);
  133.                      break;
  134.                   }
  135.                }
  136.             }
  137. #endif
  138.             break;
  139.  
  140.         case WM_VSCROLL:
  141.             ScrollIt(ThisDoc,wParam,lParam);
  142.             break;
  143.  
  144.          case WM_PAINT:
  145.           {
  146.             HANDLE hBlock;
  147.             unsigned int Offset, MyLen, width;
  148.             int VertLines, HorzChars;
  149.             int EndofDoc = FALSE;
  150.             int RangeHigh, CurPos;
  151.             int RestX;
  152.             char far *textptr;
  153.             TypArticle far *MyArt;
  154.             TypBlock far *BlockPtr;
  155.             TypLine far *LinePtr;
  156.             HANDLE hBlackBrush;
  157.             DWORD MyColors[4], MyBack[4];
  158.             int MyColorMask = 1, PrevColorMask = MyColorMask;
  159. #ifdef MAC
  160.             RECT myRect;
  161.             POINT myPoint;
  162. #endif
  163.  
  164.             hDC = BeginPaint (hWnd, &ps);
  165.  
  166.             GetClientRect(hWnd, &myRect);
  167.             SelectObject(hDC,hFont);
  168.             VertLines = ThisDoc->ScYLines;
  169.             HorzChars = ThisDoc->ScXChars;
  170.  
  171.             LockLine(ThisDoc->hCurTopScBlock,ThisDoc->TopScOffset,ThisDoc->TopScLineID,
  172.              &BlockPtr,&LinePtr);
  173.  
  174.             /* Update the scroll bar thumb position.                 */
  175.  
  176.             CurPos = ThisDoc->TopLineOrd;
  177.             if(CurPos<0) CurPos = 0;
  178.             RangeHigh = ThisDoc->TotalLines - VertLines;
  179.             if(RangeHigh<0) RangeHigh = 0;
  180.             SetScrollRange(hWnd,SB_VERT,0,RangeHigh,FALSE);
  181.             SetScrollPos  (hWnd,SB_VERT,CurPos,TRUE);
  182. #ifdef MAC
  183.             myRect.right = ThisDoc->DocClipRect.right;
  184.             myRect.top = 0;
  185.             myRect.bottom = LineHeight;
  186. #endif
  187.             /* Now paint this stuff on the screen for debugging. */
  188.  
  189.             X = SideSpace;
  190.             Y = StartPen;
  191.  
  192.             if(LinePtr->length != END_OF_BLOCK)
  193.              do {
  194.                MyLen = LinePtr->length - sizeof(TypLine) - sizeof(int) - 1;
  195.                MyLen = ((TypText far *)((char far *) LinePtr +
  196.                 sizeof(TypLine)))->NameLen;
  197.                textptr = (char far *) LinePtr + sizeof(TypLine)+ sizeof(TypText);
  198.  
  199.                /* Now write out the line.                            */
  200.  
  201. #if 1
  202.                width = LOWORD(GetTextExtent(hDC,textptr,MyLen));
  203. #else
  204.       width = CharWidth * MyLen;
  205. #endif
  206.                TextOut(hDC,X,Y,textptr,MyLen);
  207. #ifdef MAC
  208.                GetPen(&myPoint);
  209.                myRect.left = myPoint.h;
  210.                FillRect(&myRect,white);
  211.  
  212.                myRect.top += LineHeight;
  213.                myRect.bottom += LineHeight;
  214. #else
  215.                RestX = X + width;
  216.                PatBlt(hDC,RestX,Y,myRect.right-RestX,LineHeight,PATCOPY);
  217. #endif
  218. #if 0
  219.                if(MyLen < HorzChars) {
  220.                   RestX = X + width;
  221. #if 0
  222.                   TextOut(hDC,RestX,Y,Blanks,MAXINTERNALLINE);
  223. #endif
  224.                   PatBlt(hDC,RestX,Y,myRect.right-RestX,LineHeight,PATCOPY);
  225.                }
  226. #endif
  227.                Y += LineHeight;
  228.             } while(--VertLines>0 && NextLine(&BlockPtr,&LinePtr) );
  229.  
  230.             /* We've reached the end of the data to be displayed     */
  231.             /* on this window.  If there's more screen real estate   */
  232.             /* left, just blank it out.                              */
  233.  
  234. #if !MAC
  235.             PatBlt(hDC,0,Y,myRect.right,myRect.bottom-Y,PATCOPY);
  236. #else
  237.          /* myRect.top = myRect.top + LineHeight; */
  238.             myRect.bottom = ThisDoc->DocClipRect.bottom;
  239.             myRect.left = 0;
  240.             EraseRect(& myRect);
  241. #endif
  242. #if 0
  243.             while(VertLines-- > -1) {
  244.                TextOut(hDC,X,Y,Blanks,HorzChars);
  245.                Y += LineHeight;
  246.             }
  247. #endif
  248.  
  249.             UnlockLine(BlockPtr,LinePtr,&hBlock,&Offset,&MyLineID);
  250.             EndPaint(hWnd, &ps);
  251.             break;
  252.          }
  253.  
  254.         case WM_COMMAND:
  255.             switch(wParam) {
  256.                 case IDM_EXIT:
  257.                     DestroyWindow(hWnd);
  258.                     break;
  259.  
  260.                 case IDM_SAVE:
  261.                   if(strcmp(SaveArtFileName,"")) {
  262.                      SaveArtAppend = TRUE;
  263.                      MRRWriteDocument(ActiveArticleDoc,sizeof(TypText),SaveArtFileName,SaveArtvRef,SaveArtAppend);
  264.                        /* Should the 0 be sizeof(TypText) ? */
  265.                      break;
  266.                   } else {
  267.                      goto saveas;
  268.                   }
  269.  
  270.                 case IDM_SAVEAS:
  271. saveas:;
  272. #ifndef MAC
  273.                   if(DialogBox(hInst,"WinVnSaveArt",hWnd,lpfnWinVnSaveArtDlg)) {
  274.                      InvalidateRect(hWnd,NULL,TRUE);
  275.                   }
  276. #else
  277.                   result = MySaveAs(SaveArtFileName,&SaveArtvRef,&SaveArtAppend);
  278.                   if(result) {
  279.                      MRRWriteDocument(ActiveArticleDoc,sizeof(TypText),SaveArtFileName,SaveArtvRef,SaveArtAppend);
  280.                   }
  281. #endif
  282.                    break;
  283.  
  284.                 case IDM_NEXT_ARTICLE:
  285.                   GroupDoc = ThisDoc->ParentDoc;
  286.                   if(GroupDoc) {
  287.                      LockLine(GroupDoc->hLastSeenBlock,GroupDoc->LastSeenOffset,GroupDoc->LastSeenLineID,
  288.                       &BlockPtr,&LinePtr);
  289.                      if(NextLine(&BlockPtr,&LinePtr)){
  290.                         ViewArticle(GroupDoc,BlockPtr,LinePtr,TRUE);
  291.                         /* ViewArticle unlocks the block itself. */
  292.                      } else {
  293.                         MessageBox(hWnd,"No more articles","That's all!",MB_OK);
  294.                         GlobalUnlock(BlockPtr->hCurBlock);
  295.                      }
  296.                   } else {
  297.                      MessageBox(hWnd,"Sorry--you must have the group window around\n\
  298. for me to be able to find the next article","Can't find next article",MB_OK);
  299.                   }
  300.                   break;
  301.  
  302.                case IDM_FIND_NEXT_SAME:
  303.                   GroupDoc = ThisDoc->ParentDoc;
  304.                   if(GroupDoc) {
  305.                      /* Locate the line in the parent Group document */
  306.                      /* containing the subject of this article.      */
  307.                      /* Make this subject our search pattern,        */
  308.                      /* after stripping off a leading "Re: "         */
  309.                      /* if necessary.                                */
  310.  
  311.                      LockLine(ThisDoc->hParentBlock,ThisDoc->ParentOffset,ThisDoc->ParentLineID,
  312.                         &BlockPtr,&LinePtr);
  313.                      cptr = (char far *)LinePtr + sizeof(TypLine) + sizeof(TypArticle);
  314.                      if(mylstrncmp(cptr,"Re: ",4)==0) cptr += 4;
  315.                      mylstrncpy(GroupDoc->SearchStr,cptr,MAXFINDSTRING);
  316.                      GlobalUnlock(BlockPtr->hCurBlock);
  317.  
  318.                      /* Now try to find another line in the group    */
  319.                      /* document that contains this subject.          */
  320.  
  321.                      GroupDoc->hFindBlock = ThisDoc->hParentBlock;
  322.                      GroupDoc->FindOffset = ThisDoc->ParentOffset;
  323.                      GroupDoc->FindLineID = ThisDoc->ParentLineID;
  324.                      FindDoc = GroupDoc;
  325.                      result = DoFind(FALSE);
  326.  
  327.                      /* If such an article was found, display it.    */
  328.                      if(result) {
  329.                         LockLine(FindDoc->hFindBlock,FindDoc->FindOffset,FindDoc->FindLineID,
  330.                          &BlockPtr,&LinePtr);
  331.                         ViewArticle(FindDoc,BlockPtr,LinePtr,TRUE);
  332.                      } else {
  333.                         MessageBox(hWnd,"No more articles with this subject.","None found",MB_OK);
  334.                      }
  335.                   }
  336.                   break;
  337.  
  338.                case IDM_FOLLOWUP:
  339.                   CreatePostingWnd(ThisDoc,DOCTYPE_POSTING);
  340.                   break;
  341.  
  342.                case IDM_MAIL:
  343.                   CreatePostingWnd(ThisDoc,DOCTYPE_MAIL);
  344.                   break;
  345.             }
  346.             break;
  347.  
  348.         default:
  349.             return (DefWindowProc(hWnd, message, wParam, lParam));
  350.     }
  351.     return (0);
  352. }
  353.